package miko.mikoplex;

import miko.mikoplex.controller.GameBoardControler;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.material.MaterialList;
import com.jme3.math.Matrix3f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;

/**
 * A very simple game board, with camera control
 */
public class Main extends SimpleApplication {

	public static void main(String[] args) {
		Main app = new Main();
		app.start();
	}
	
	GameBoardControler gbc;

	@SuppressWarnings("deprecation")
	@Override
	public void simpleInitApp() {
		cam.setLocation(new Vector3f(0f, 0f, 100f));
		cam.lookAt(new Vector3f(0f, 0f, 0f), new Vector3f(0f, 1f, 0f));
		assetManager.registerLocator("assets", FileLocator.class.getName());
		
		gbc = new GameBoardControler("XXX\n" + "XXX\n" + "X X\n", assetManager);
		rootNode.attachChild(gbc.getGameBoardNode());
		
		flyCam.setEnabled(false);

		inputManager.addMapping("ZoomOut", new KeyTrigger(KeyInput.KEY_MINUS));
		inputManager.addMapping("ZoomIn", new KeyTrigger(KeyInput.KEY_EQUALS));
		inputManager.addMapping("MoveLeft", new KeyTrigger(KeyInput.KEY_LEFT));
		inputManager.addMapping("MoveRight", new KeyTrigger(KeyInput.KEY_RIGHT));
		inputManager.addMapping("MoveUp", new KeyTrigger(KeyInput.KEY_UP));
		inputManager.addMapping("MoveDown", new KeyTrigger(KeyInput.KEY_DOWN));
		
		inputManager.addListener(new AnalogListener() {
			@Override
			public void onAnalog(String name, float value, float tpf) {
				rootNode.setLocalScale(rootNode.getLocalScale().x-value);
			}
		}, "ZoomOut");
		inputManager.addListener(new AnalogListener() {
			@Override
			public void onAnalog(String name, float value, float tpf) {
				rootNode.setLocalScale(rootNode.getLocalScale().x+value);
			}
		}, "ZoomIn");
		inputManager.addListener(new AnalogListener() {
			@Override
			public void onAnalog(String name, float value, float tpf) {
				Vector3f v = cam.getLocation();
				v.x -= value*10; 
				cam.setLocation(v);
			}
		}, "MoveLeft");
		inputManager.addListener(new AnalogCamMover(cam, new float[] {10f}), "MoveRight");
		inputManager.addListener(new AnalogCamMover(cam, new float[] {0f, 10f}), "MoveUp");
		inputManager.addListener(new AnalogCamMover(cam, new float[] {0f,-10f}), "MoveDown");
	}
}